// 导入 Element Plus 中英文语言包
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import en from 'element-plus/es/locale/lang/en'
import defaultSettings from '~/setting'

export const useAppStore = defineStore('app', {
  state: () => ({
    device: useStorage('device', 'desktop'),
    size: useStorage<any>('size', defaultSettings.size),
    sidebarStatus: useStorage('sidebarStatus', 'closed'),
    sidebar: {
      opened: false,
      withoutAnimation: false,
    },
    language: useStorage('language', defaultSettings.language),
    activeTopMenuPath: useStorage('activeTopMenuPath', ''),
  }),
  getters: {
    locale(state) {
      if (state.language === 'en')
        return en
      else
        return zhCn
    },
  },
  actions: {
    toggleDevice(val: string) { // 切换移动端 / PC 端
      this.device = val
    },
    closeSideBar() {
      this.sidebar.opened = false
      this.sidebarStatus = 'closed'
    },
    openSideBar() {
      this.sidebar.opened = true
      this.sidebarStatus = 'open'
    },
  },
})
